package cn.kgc.vue.service.impl;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.dto.StudentDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.Student;
import cn.kgc.vue.service.StudentService;
import cn.kgc.vue.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService{

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public ResponseResult getStudentPage(StudentDTO studentDTO) {

        ResponseResult responseResult = new ResponseResult();

        Page<Student> studentPage = new Page<>(studentDTO.getPage(), studentDTO.getLimit());

        LambdaQueryWrapper<Student> lambda = new LambdaQueryWrapper<>();
        lambda.eq(StringUtils.isNotEmpty(studentDTO.getStudentNo()), Student::getStudentNo,studentDTO.getStudentNo())
                .like(StringUtils.isNotEmpty(studentDTO.getName()),Student::getName,studentDTO.getName());

        studentMapper.selectPage(studentPage,lambda);
        // 获取分页数据
        List<Student> records = studentPage.getRecords();
        long total = studentPage.getTotal();
        responseResult.setCount(total);
        responseResult.setData(records);
        responseResult.setCode(0);
        responseResult.setMsg("查询成功");
        return responseResult;
    }
}




